import CryptoJS from 'crypto-js';

const keyWord = 'shopkey-password';
// 加密
export const encryptO = (word) => {
    // 获取当前时间
    const time =  Date.now();
    // 转码
    const wordStr = CryptoJS.enc.Utf8.parse(time+""+word)
    const keyStr =  CryptoJS.enc.Utf8.parse(keyWord)
    // 加密
    const encrypted =CryptoJS.AES.encrypt(wordStr,keyStr,{
        mode: CryptoJS.mode.ECB, //加密模式
        padding: CryptoJS.pad.Pkcs7 //如何补零
    })
    return encrypted.toString()
}

// 解密
export const decryptO = (word) => {
    const keyStr =  CryptoJS.enc.Utf8.parse(keyWord)
    const decrypted = CryptoJS.AES.decrypt(word, keyStr,{
        mode: CryptoJS.mode.ECB, //解密模式
        padding: CryptoJS.pad.Pkcs7 //如何补零
    })
    // return decrypted.toString(CryptoJS.enc.Utf8)
    return CryptoJS.enc.Utf8.stringify(decrypted).toString()
}